#pragma once

#include "Object.h"

class PineTree : public Object
{
private:
	void setTrunkColorMaterial()
	{
		GLfloat mat_ambient[] = {0.4f, 0.25f, 0.0f, 1.0f};
		GLfloat mat_diffuse[] = {0.4f, 0.25f, 0.0f, 1.0f};
		GLfloat mat_specular[] = {0.1f, 0.1f, 0.1f, 1.0f};
		GLfloat mat_shininess[] = {0.5f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void setLeavesColorMaterial()
	{
		GLfloat mat_ambient[] = {0.0f, 0.32f, 0.0f, 1.0f};
		GLfloat mat_diffuse[] = {0.0f, 0.32f, 0.0f, 1.0f};
		GLfloat mat_specular[] = {0.0f, 0.32f, 0.0f, 1.0f};
		GLfloat mat_shininess[] = {1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void drawTrunk()
	{
		float height = 0.25;
		float radius = .06;
		
		setTrunkColorMaterial();

		GLUquadricObj *trunk;
		trunk = gluNewQuadric();
		glRotatef(-90, 1, 0, 0);
		gluCylinder(trunk, radius, radius, height, 32, 32);
	}

	void drawTop()
	{
		float height = 0.33;
		float radius = .33;

		setLeavesColorMaterial();

		// Bottom section
		glPushMatrix();
		glTranslated(0, .25, 0);
		glRotatef(-90,1,0,0);
		glutSolidCone(radius, height, 10, 10);
		glRotatef(-180,1,0,0);
		glutSolidCone(radius, height/5, 10, 10);
		glPopMatrix();

		// Middle section
		glPushMatrix();
		glTranslated(0, .5, 0);
		glRotatef(-90,1,0,0);
		glutSolidCone(2*radius/3, height, 10, 10);
		glRotatef(-180,1,0,0);
		glutSolidCone(2*radius/3, height/5, 10, 10);
		glPopMatrix();

		// Top section
		glPushMatrix();
		glTranslated(0, .75, 0);
		glRotatef(-90,1,0,0);
		glutSolidCone(radius/3, height, 10, 10);
		glRotatef(-180,1,0,0);
		glutSolidCone(radius/3, height/5, 10, 10);
		glPopMatrix();
	}

public:
	PineTree(float x, float y, float z, float size)
	{
		setPosition(x, y, z);
		setSize(size);
	}

	void draw()
	{
		glPushMatrix();

		// Transformations
		glScaled(size,size,size);
		glTranslated(position.x, position.y, position.z);
		glRotatef(rotation, 0, 1, 0);

		drawTop();

		drawTrunk();

		glPopMatrix();
	}

	void update(float delta) {}
};
